<?php

use app\admin\controller\StatisticsController;
use Webman\Route;

Route::group('/admin', function () {
    Route::group('/core', function () {
        Route::get('/captcha', [app\admin\controller\LoginController::class, 'captcha']);
        Route::post('/login', [app\admin\controller\LoginController::class, 'login']);
        Route::post('/refresh-token', [app\admin\controller\LoginController::class, 'refreshToken']);

        Route::get("/system/dictAll", [app\admin\controller\SystemController::class, 'dictAll']);
        Route::get('/system/user', [app\admin\controller\SystemController::class, 'userInfo']);
        Route::get('/system/statistics', [app\admin\controller\SystemController::class, 'statistics']);
        Route::get('/system/loginChart', [app\admin\controller\SystemController::class, 'loginChart']);
        Route::get('/system/notice', [app\admin\controller\SystemController::class, 'systemNotice']);
        Route::get('/system/clearAllCache', [app\admin\controller\SystemController::class, 'clearAllCache']);

        Route::get("/system/getResourceList", [app\admin\controller\SystemController::class, 'getResourceList']);
        Route::post("/system/saveNetworkImage", [app\admin\controller\SystemController::class, 'saveNetworkImage']);
        Route::post("/system/uploadImage", [app\admin\controller\SystemController::class, 'uploadImage']);
        Route::post("/system/uploadFile", [app\admin\controller\SystemController::class, 'uploadFile']);
        Route::get("/system/downloadById", [app\admin\controller\SystemController::class, 'downloadById']);
        Route::get("/system/downloadByHash", [app\admin\controller\SystemController::class, 'downloadByHash']);
        Route::get("/system/getUserList", [app\admin\controller\SystemController::class, 'getUserList']);
        Route::post("/system/getUserInfoByIds", [app\admin\controller\SystemController::class, 'getUserInfoByIds']);
        Route::get("/system/getLoginLogList", [app\admin\controller\SystemController::class, 'getLoginLogList']);
        Route::get("/system/getOperationLogList", [app\admin\controller\SystemController::class, 'getOperationLogList']);

        // 用户管理
        fastRoute("user", \app\admin\controller\system\SystemUserController::class);
        Route::post("/user/updateInfo", [\app\admin\controller\system\SystemUserController::class, 'updateInfo']);
        Route::post("/user/modifyPassword", [\app\admin\controller\system\SystemUserController::class, 'modifyPassword']);
        Route::post("/user/clearCache", [\app\admin\controller\system\SystemUserController::class, 'clearCache']);
        Route::post("/user/initUserPassword", [\app\admin\controller\system\SystemUserController::class, 'initUserPassword']);

        // 角色管理
        fastRoute('role', \app\admin\controller\system\SystemRoleController::class);
        Route::get("/role/accessRole", [\app\admin\controller\system\SystemRoleController::class, 'accessRole']);
        Route::get("/role/getMenuByRole", [\app\admin\controller\system\SystemRoleController::class, 'getMenuByRole']);
        Route::post("/role/menuPermission", [\app\admin\controller\system\SystemRoleController::class, 'menuPermission']);
        Route::get("/role/getDeptByRole", [\app\admin\controller\system\SystemRoleController::class, 'getDeptByRole']);
        Route::post("/role/dataPermission", [\app\admin\controller\system\SystemRoleController::class, 'dataPermission']);


        // 部门管理
        fastRoute("dept", \app\admin\controller\system\SystemDeptController::class);
        Route::get("/dept/accessDept", [\app\admin\controller\system\SystemDeptController::class, 'accessDept']);
        Route::get("/dept/leaders", [\app\admin\controller\system\SystemDeptController::class, 'leaders']);
        Route::post("/dept/addLeader", [\app\admin\controller\system\SystemDeptController::class, 'addLeader']);
        Route::delete("/dept/delLeader", [\app\admin\controller\system\SystemDeptController::class, 'delLeader']);

        // 岗位管理
        fastRoute('post', \app\admin\controller\system\SystemPostController::class);
        Route::get("/post/accessPost", [\app\admin\controller\system\SystemPostController::class, 'accessPost']);
        Route::post("/post/downloadTemplate", [app\admin\controller\system\SystemPostController::class, 'downloadTemplate']);

        // 公司管理
        fastRoute('company', \app\admin\controller\CompanyController::class);
        Route::get('/company/accounts', [\app\admin\controller\CompanyController::class, 'companyAccountList']);
        Route::post('/company/saveAccount', [\app\admin\controller\CompanyController::class, 'companyAccountSave']);
        Route::put('/company/updateAccount', [\app\admin\controller\CompanyController::class, 'companyAccountUpdate']);
        Route::delete('/company/deleteAccount', [\app\admin\controller\CompanyController::class, 'companyAccountDelete']);

        // 菜单管理
        fastRoute('menu', \app\admin\controller\system\SystemMenuController::class);
        Route::get("/menu/accessMenu", [\app\admin\controller\system\SystemMenuController::class, 'accessMenu']);
        // 字典类型管理
        fastRoute('dictType', \app\admin\controller\system\SystemDictTypeController::class);
        // 字典数据管理
        fastRoute('dictData', \app\admin\controller\system\SystemDictDataController::class);
        // 附件管理
        fastRoute('attachment', \app\admin\controller\system\SystemAttachmentController::class);
        // 通知公告
        fastRoute('notice', \app\admin\controller\system\SystemNoticeController::class);

        // 系统设置
        fastRoute('configGroup', \app\admin\controller\system\SystemConfigGroupController::class);
        Route::post("/configGroup/email", [\app\admin\controller\system\SystemConfigGroupController::class, 'email']);
        fastRoute('config', \app\admin\controller\system\SystemConfigController::class);
        Route::post("/config/batchUpdate", [\app\admin\controller\system\SystemConfigController::class, 'batchUpdate']);

        // 日志管理
        Route::get("/system/monitor", [app\admin\controller\SystemController::class, 'getServerInfo']);
        Route::get("/logs/getLoginLogPageList", [\app\admin\controller\system\SystemLogController::class, 'getLoginLogPageList']);
        Route::delete("/logs/deleteLoginLog", [\app\admin\controller\system\SystemLogController::class, 'deleteLoginLog']);
        Route::get("/logs/getOperLogPageList", [\app\admin\controller\system\SystemLogController::class, 'getOperLogPageList']);
        Route::delete("/logs/deleteOperLog", [\app\admin\controller\system\SystemLogController::class, 'deleteOperLog']);
        Route::get("/email/index", [\app\admin\controller\system\SystemMailController::class, 'index']);
        Route::delete("/email/destroy", [\app\admin\controller\system\SystemMailController::class, 'destroy']);

        // 数据表维护
        Route::get("/database/index", [\app\admin\controller\system\DataBaseController::class, 'index']);
        Route::get("/database/recycle", [\app\admin\controller\system\DataBaseController::class, 'recycle']);
        Route::delete("/database/delete", [\app\admin\controller\system\DataBaseController::class, 'delete']);
        Route::post("/database/recovery", [\app\admin\controller\system\DataBaseController::class, 'recovery']);
        Route::get("/database/dataSource", [\app\admin\controller\system\DataBaseController::class, 'source']);
        Route::get("/database/detailed", [\app\admin\controller\system\DataBaseController::class, 'detailed']);
        Route::post("/database/optimize", [\app\admin\controller\system\DataBaseController::class, 'optimize']);
        Route::post("/database/fragment", [\app\admin\controller\system\DataBaseController::class, 'fragment']);

        fastRoute('region', \app\admin\controller\system\SystemRegionController::class);
        Route::get("/region/getAll", [\app\admin\controller\system\SystemRegionController::class, 'getAllRegion']);
    });

    Route::group('/tool', function () {
        // 定时任务
        fastRoute('crontab', \app\admin\controller\tool\CrontabController::class);
        Route::post("/crontab/run", [\app\admin\controller\tool\CrontabController::class, 'run']);
        Route::get("/crontab/logPageList", [\app\admin\controller\tool\CrontabController::class, 'logPageList']);
        Route::delete('/crontab/deleteCrontabLog', [\app\admin\controller\tool\CrontabController::class, 'deleteCrontabLog']);
    });

    Route::post('/sync', [\app\admin\controller\SyncController::class, 'syncInfo']);

    Route::group('/company/menus', function () {
        Route::get("/index", [\app\admin\controller\CompanyMenusController::class, 'index']);
        Route::post("/save", [\app\admin\controller\CompanyMenusController::class, 'save']);
        Route::put("/update", [\app\admin\controller\CompanyMenusController::class, 'update']);
        Route::delete('/destroy', [\app\admin\controller\CompanyMenusController::class, 'destroy']);
    });

    // CRM设置管理
    Route::group('/crm', function () {
        // 分组管理
        Route::get('/crm_settings', [app\admin\controller\crm\CrmSettingsController::class, 'getCrmSetting']);
        Route::post('/crm_settings_save', [app\admin\controller\crm\CrmSettingsController::class, 'saveCrmSetting']);

        // 客户管理
        fastRoute('customer', \app\admin\controller\crm\CustomersController::class);
        Route::post('/customer/disabled', [\app\admin\controller\crm\CustomersController::class, 'disabledCustomer']);
        Route::get('/customer_log', [\app\admin\controller\crm\CustomersController::class, 'customerLogs']);
        Route::get('/customer_followups', [\app\admin\controller\crm\CustomersController::class, 'customerFollowups']);
        Route::get('/customer_attachments', [\app\admin\controller\crm\CustomersController::class, 'customerAttachments']);
        Route::delete('/delete_attachment', [\app\admin\controller\crm\CustomersController::class, 'deleteAttachment']);
        Route::post('/upload_attachment', [\app\admin\controller\crm\CustomersController::class, 'uploadAttachment']);
        Route::post('/assign_manager', [\app\admin\controller\crm\CustomersController::class, 'assignManager']);

        // 客户跟进记录管理
        fastRoute('followups', \app\admin\controller\crm\CrmFollowUpsController::class);
    });

    // 统计报表
    Route::group('/statistics', function () {
        Route::get("/cargo", [\app\admin\controller\StatisticsController::class, 'getCargoList']);
        Route::get("/inventory", [\app\admin\controller\StatisticsController::class, 'getInventoryList']);
        Route::get("/performance", [\app\admin\controller\StatisticsController::class, 'getPerformanceList']);
        Route::get("/business_data", [\app\admin\controller\StatisticsController::class, 'getBusinessDataList']);
        Route::get("/business_detail", [\app\admin\controller\StatisticsController::class, 'getBusinessDetail']);
        Route::post("/save_business_detail", [\app\admin\controller\StatisticsController::class, 'saveBusinessDetail']);
    });

    // 经销商申请
    Route::group('/serve', function () {
        Route::get('/approving', [\app\admin\controller\DealerAssistanceApplicationController::class, 'index']);
        Route::get('/approving/read', [\app\admin\controller\DealerAssistanceApplicationController::class, 'read']);
        Route::put('/approving/update', [\app\admin\controller\DealerAssistanceApplicationController::class, 'update']);
        Route::post('/approving/export', [\app\admin\controller\DealerAssistanceApplicationController::class, 'export']);
    });

    // 运营公告
    fastRoute('operate_notice', \app\admin\controller\MessageNotificationController::class);

    // 通用api
    Route::group('/api', function () {
        Route::get('/region', [\app\admin\controller\ApiController::class, 'getRegion']);
        Route::get('/user', [\app\admin\controller\ApiController::class, 'getUserList']);
        Route::get('/field_types', [\app\admin\controller\ApiController::class, 'getFieldTypes']);
        Route::get('/field_groups', [\app\admin\controller\ApiController::class, 'getFieldGroups']);
        Route::get('/validation-rules', [\app\admin\controller\ApiController::class, 'getValidationRules']);
        Route::get('/customer_list_fields', [\app\admin\controller\ApiController::class, 'getCustomerListFields']);
        Route::get('/customer_list', [\app\admin\controller\ApiController::class, 'getCustomerList']);
        Route::get('/dept_list', [\app\admin\controller\ApiController::class, 'getDeptList']);
        Route::get('/company_list', [\app\admin\controller\ApiController::class, 'getCompanyList']);
        Route::get('/dealer_list', [\app\admin\controller\ApiController::class, 'getDealerList']);
        Route::get('/company_role_list', [\app\admin\controller\ApiController::class, 'getCompanyUserRoleList']);
        Route::get('/operate_notice_type', [\app\admin\controller\ApiController::class, 'getOperateNoticeType']);
    });
});

Route::disableDefaultRoute();
